//
//  CHCheckCell.m
//  CarFile
//
//  Created by 陈浩 on 2017/7/5.
//  Copyright © 2017年 陈浩. All rights reserved.
//

#import "CHCheckCell.h"
@interface CHCheckCell()

@property (nonatomic ,strong) UIImageView *photoImgView;
@property (nonatomic ,strong) UILabel *titleLabel;
@property (nonatomic ,strong) UILabel *timeLabel;
@property (nonatomic ,strong) UIImageView *resultImgView;
@property (nonatomic ,strong) UILabel *resultLabel;
@end
@implementation CHCheckCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}


+(instancetype) cellForTableView:(UITableView *)tableView{
    static NSString *ID = @"CHCheckCell";
    CHCheckCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[CHCheckCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
    
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    return self;
    
}

-(void)setupUI{
    
    self.photoImgView = [[UIImageView alloc] init];
    self.photoImgView.layer.cornerRadius = 5;
    self.photoImgView.layer.masksToBounds = YES;
    self.photoImgView.image = [UIImage imageNamed:@"img_01"];
    [self.contentView addSubview:self.photoImgView];
    
    self.titleLabel = [[UILabel alloc] init];
//    self.titleLabel.text = @"杭州车路湾汽车修理有限公司";
    self.timeLabel.textColor = [UIColor colorWithHexString:@"333333" alpha:1.0f];
    self.titleLabel.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:self.titleLabel];
    

    
    self.timeLabel = [[UILabel alloc] init];
    self.timeLabel.font = [UIFont systemFontOfSize:12];
    self.timeLabel.textColor = [UIColor colorWithHexString:@"999999" alpha:1.0f];
    [self.contentView addSubview:self.timeLabel];
    
    self.resultImgView = [[UIImageView alloc] init];
    [self.contentView addSubview:self.resultImgView];
    
    
    self.resultLabel = [[UILabel alloc] init];
    self.resultLabel.textColor = [UIColor colorWithHexString:@"999999" alpha:1.0f];
    self.resultLabel.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:self.resultLabel];

}

-(void)setModel:(CHCheckModel *)model{
    _model = model;
    [self.photoImgView sd_setImageWithURL:[NSURL URLWithString:model.companyphoto] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    self.titleLabel.text = model.name;
    self.timeLabel.text = [NSString stringWithFormat:@"审核时间：%@",model.examine];
    if ([model.state isEqualToString:@"1"]) {  // 通过
        self.resultImgView.image = [UIImage imageNamed:@"pass"];
        self.resultLabel.textColor = [UIColor redColor];
        self.resultLabel.text = @"已通过";
        
    }else{
        self.resultImgView.image = [UIImage imageNamed:@"refused"];
        self.resultLabel.textColor = [UIColor colorWithHexString:@"999999" alpha:1.0f];
        self.resultLabel.text = @"被拒绝";
    }
}

-(void)layoutSubviews{
    [super layoutSubviews];
    
    self.photoImgView.frame = CGRectMake(10, 15, 130, 90);
    self.titleLabel.frame = CGRectMake(CGRectGetMaxX(self.photoImgView.frame) +10, 15, UIScreenW - CGRectGetMaxX(self.photoImgView.frame) - 15, 30);
    self.timeLabel.frame = CGRectMake(CGRectGetMaxX(self.photoImgView.frame)+10, CGRectGetMaxY(self.titleLabel.frame)+5, UIScreenW - CGRectGetMaxX(self.photoImgView.frame) - 5, 15);
    self.resultImgView.frame = CGRectMake(CGRectGetMaxX(self.photoImgView.frame) +10, CGRectGetMaxY(self.timeLabel.frame)+12, 11, 11);
    self.resultLabel.frame = CGRectMake(CGRectGetMaxX(self.resultImgView.frame)+5, CGRectGetMaxY(self.timeLabel.frame) +10, UIScreenW - CGRectGetMaxX(self.resultImgView.frame) - 5, 15);
    
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
